package org.example.spring.controller.Admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.spring.domain.dto.OrderDTO;
import org.example.spring.domain.pojo.Order;
import org.example.spring.domain.pojo.Result;
import org.example.spring.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "根据状态获取订单")
    @GetMapping("/getOrdersByStatus")
    public Result getOrderByStatus(@RequestParam(required = false) Integer status) {
        ArrayList<Order> orders = orderService.getOrderByStatus(status);
        return Result.success(orders);
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/getOrdersByPage")
      public Result getOrdersByPage(OrderDTO orderDTO) {
        OrderDTO od= orderService.getOrdersByPage(orderDTO);
        return Result.success(od);
    }

    @ApiOperation(value = "修改订单状态")
    @PostMapping("/updateOrderStatus")
    public Result updateOrderStatus(@RequestParam Integer orderId, @RequestParam Integer status) {
        orderService.updateOrderStatus(orderId, status);
        return Result.success("修改成功");
    }




}
